﻿using Echo.Context.UltiProNet.Contexts;
using Echo.Core.TestAbstraction.WebUITest.MbUnit;
using Echo.Models.UltiProNet;
using Echo.Models.UltimateSoftware.WebUITest.MbUnit;
using MbUnit.Framework;

/*************************************************************************************************************************************
 * Created by:     Charles Turiño
 * Date created:   04/27/2012
 * Modified by: 
 * Date modified: 
 * Reason:         
 * ULTI-75065 JIRA Description.
 * 
 * ULTI-20033 - Peter can reset the unsaved entries or changes he has made on the page
 *            - Peter can cancel the entries or changes he has made on the page
 *              -> User hits cancel, then no and stays on the page
 *              -> User hits cancel, then yes and leaves the page
 *            - Peter can view a print preview of the tax main details.
 *            - Peter can view online help for the tax main details.
 **************************************************************************************************************************************/
namespace Echo.Automation.Compliance.BusinessRules.Taxes
{
    [TestFixture]
    [Header("Config")]
    [Config(".NET")]
    [Author("Charles Turiño", "charles_turino@ultimatesoftware.com")]
    [Category("Taxes")]
    [Category("Business Rules")]
    public class TaxesDetailLinkedSUICodes : MbUnitAutomatedTest
    {
        UltiPro UltiPro;
        string empIDNum = "FL-.123.-456789";

        [TearDown]
        public void TearDown()
        {
            UltiPro.Browser.Quit();
        }

        [SetUp]
        public void Setup()
        {
            /* Launch and login was added here because of the echo bug that doesn't allow the
             * focus back onto the original browser window
             * */
            UltiPro = Launch<UltiPro>();
            UltiPro.Pages.Login.LoginAs("merrillg", "password", Config.LanguageCode);
            UltiPro.Pages.CompanySelector.ChooseCompanies("CALEN", "C0014");

            UltiPro.Menu.SystemConfiguration.Click(menu => menu.BusinessRules);
            UltiPro.Pages.BusinessRulesSummary.BusinessRulesSummaryGrid.Find(searchFilter => searchFilter.BusinessRulesNameFilter,
                FilterType.Is, "Taxes");
            UltiPro.Pages.BusinessRulesSummary.BusinessRulesSummaryGrid.Row(columnHeader => columnHeader.BusinessRulesLink, "Taxes").Click(link => link.BusinessRulesLink);
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Find(searchFilter => searchFilter.CodeFilter, FilterType.Is, "FLSUIER");
            UltiPro.Pages.BusinessRuleDetail.BusinessRuleDetailGrid.Row(columnHeader => columnHeader.Code, "FLSUIER",
                columnHeader => columnHeader.Company, "Chequemates US 1").Click(columnHeader => columnHeader.Code);
        }

        // This method will validate that the reset button on the taxes details page works correctly
        [Test]
        public void ValidateResetButton()
        {
            UltiPro.Pages.TaxCodeContributionRate.Is(x => x.PageHeaderLabel, "innerHtml", "View/Change Taxes");
            UltiPro.Pages.TaxCodeContributionRate.Set(empID => empID.EmployerIdNumberTextBox, empIDNum);
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(btn => btn.Reset);
            UltiPro.Pages.TaxCodeContributionRate.Is(empID => empID.EmployerIdNumberTextBox, "innerHtml", string.Empty);
        }

        // This method will validate that the cancel button on the taxes details page works correctly
        [Test]
        public void ValidateCancelButton()
        {
            UltiPro.Pages.TaxCodeContributionRate.Is(x => x.PageHeaderLabel, "innerHtml", "View/Change Taxes");
            UltiPro.Pages.TaxCodeContributionRate.Set(empID => empID.EmployerIdNumberTextBox, empIDNum);
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(btn => btn.Cancel);
            UltiPro.Alert.Accept();
            UltiPro.Pages.BusinessRuleDetail.Is(x => x.PageHeaderLabel, "innerHtml", "Taxes");
        }

        // This method will validate that the print button on the taxes details page works correctly
        [Test]
        public void ValidatePrintButton()
        {
            UltiPro.Pages.TaxCodeContributionRate.Is(x => x.PageHeaderLabel, "innerHtml", "View/Change Taxes");
            UltiPro.Pages.TaxCodeContributionRate.Set(empID => empID.EmployerIdNumberTextBox, empIDNum);
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(btn => btn.Print);
            UltiPro.Browser.SwitchToWindow("Print Preview");
            UltiPro.Pages.PrintPreview.Click(x => x.CloseButton);
        }

        // This method will validate that the help button on the taxes details page works correctly
        [Test]
        public void ValidateHelpButton()
        {
            UltiPro.Pages.TaxCodeContributionRate.Is(x => x.PageHeaderLabel, "innerHtml", "View/Change Taxes");
            UltiPro.Pages.TaxCodeContributionRate.ButtonBar.Click(btn => btn.Help);
        }
    }
}